load("//bazel:flags.bzl", "selects")
load(
    "//bazel:skia_rules.bzl",
    "exports_files_legacy",
    "generate_cpp_files_for_headers",
    "skia_cc_deps",
    "skia_filegroup",
)

licenses(["notice"])

exports_files_legacy()

selects.config_setting_group(
    name = "android_with_ganesh_backend",
    match_all = [
        "@platforms//os:android",
        "//src/gpu:has_ganesh_backend",
    ],
)

skia_filegroup(
    name = "srcs",
    srcs = [
        "//src/android:srcs",
        "//src/base:srcs",
        "//src/codec:srcs",
        "//src/core:srcs",
        "//src/effects:srcs",
        "//src/encode:srcs",
        "//src/image:srcs",
        "//src/pathops:srcs",
        "//src/ports:srcs",
        "//src/sfnt:srcs",
        "//src/shaders:srcs",
        "//src/sksl:srcs",
        "//src/text:srcs",
        "//src/utils:srcs",
        "//src/xml:srcs",
    ] + select({
        "//src/gpu:has_ganesh_backend": [
            "//src/gpu:srcs",
            "//src/text/gpu:srcs",
        ],
        "//conditions:default": [],
    }) + select({
        "//src/svg:enable_svg_canvas_true": [
            "//src/svg:srcs",
        ],
        "//conditions:default": [],
    }) + select({
        "//src/pdf:enable_pdf_backend_true": ["//src/pdf:srcs"],
        "//conditions:default": [],
    }) + select({
        "//src/lazy:enable_discardable_memory_true": ["//src/lazy:srcs"],
        "//conditions:default": [],
    }) + select({
        "//bazel/common_config_settings:compile_generated_cpp_files_for_headers_true": [
            ":generated_srcs",
        ],
        "//conditions:default": [],
    }) + select({
        ":android_with_ganesh_backend": ["//src/image:android_srcs"],
        "//conditions:default": [],
    }),
    visibility = ["//:__pkg__"],
)

skia_filegroup(
    name = "objc_srcs",
    srcs = select({
        "//src/gpu:has_ganesh_backend": ["//src/gpu:objc_srcs"],
        "//conditions:default": [],
    }),
    visibility = ["//:__pkg__"],
)

skia_filegroup(
    name = "private_hdrs",
    srcs = [
        "//src/base:private_hdrs",
        "//src/codec:private_hdrs",
        "//src/core:private_hdrs",
        "//src/effects:private_hdrs",
        "//src/encode:private_hdrs",
        "//src/image:private_hdrs",
        "//src/opts:private_hdrs",
        "//src/pathops:private_hdrs",
        "//src/ports:private_hdrs",
        "//src/sfnt:private_hdrs",
        "//src/shaders:private_hdrs",
        "//src/sksl:private_hdrs",
        "//src/sksl/tracing:skopts_hdrs",
        "//src/text:private_hdrs",
        "//src/utils:private_hdrs",
        "//src/xml:private_hdrs",
    ] + select({
        "//src/gpu:has_ganesh_backend": [
            "//src/gpu:private_hdrs",
            "//src/text/gpu:private_hdrs",
        ],
        "//conditions:default": [],
    }) + select({
        "//src/svg:enable_svg_canvas_true": [
            "//src/svg:private_hdrs",
        ],
        "//conditions:default": [],
    }) + select({
        "//src/pdf:enable_pdf_backend_true": ["//src/pdf:private_hdrs"],
        "//conditions:default": [],
    }) + select({
        "//src/lazy:enable_discardable_memory_true": ["//src/lazy:private_hdrs"],
        "//conditions:default": [],
    }),
    visibility = [
        "//:__pkg__",
        "//src/opts:__pkg__",
    ],
)

skia_cc_deps(
    name = "deps",
    visibility = ["//:__pkg__"],
    deps = [
        "//modules/skcms",
        "//src/codec:deps",
        "//src/encode:deps",
        "//src/opts:deps",
        "//src/ports:deps",
        "//src/sksl:deps",
        "//src/xml:deps",
    ] + select({
        "//src/gpu:has_ganesh_backend": ["//src/gpu:deps"],
        "//conditions:default": [],
    }) + select({
        "//src/pdf:enable_pdf_backend_true": ["//src/pdf:deps"],
        "//conditions:default": [],
    }),
)

generate_cpp_files_for_headers(
    name = "generated_srcs",
    headers = [
        ":private_hdrs",
    ],
    # All headers listed here (using paths relative to the Skia root) will have a .cpp file
    # generated that is a copy of the header file just with a .cpp suffix so Bazel will try to
    # compile it. This allows us to run IWYU on these files.
    to_generate = [
        "src/codec/SkPixmapUtilsPriv.h",
        "src/codec/SkScalingCodec.h",
        "src/core/SkAdvancedTypefaceMetrics.h",
        "src/core/SkColorSpacePriv.h",
        "src/core/SkCoreBlitters.h",
        "src/core/SkDrawProcs.h",
        "src/core/SkMatrixPriv.h",
        "src/core/SkPathPriv.h",
        "src/core/SkRuntimeEffectPriv.h",
        "src/encode/SkICCPriv.h",
        "src/encode/SkImageEncoderFns.h",
        "src/encode/SkImageEncoderPriv.h",
        "src/gpu/AsyncReadTypes.h",
        "src/gpu/BufferWriter.h",
        "src/gpu/GpuRefCnt.h",
        "src/gpu/GpuTypesPriv.h",
        "src/gpu/KeyBuilder.h",
        "src/gpu/MutableTextureStatePriv.h",
        "src/gpu/SkRenderEngineAbortf.h",
        "src/gpu/SwizzlePriv.h",
        "src/gpu/ganesh/GrBackendSemaphorePriv.h",
        "src/gpu/ganesh/GrBackendSurfacePriv.h",
        "src/gpu/ganesh/GrClip.h",
        "src/gpu/ganesh/gl/GrGLBackendSurfacePriv.h",
        "src/gpu/ganesh/mock/GrMockSurfaceProxy.h",
        "src/gpu/ganesh/mock/GrMockTexture.h",
        "src/image/SkImageGeneratorPriv.h",
    ],
)
